<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>SP_Sales</title>
    <link rel="stylesheet" href="/static/css/layui.css">
</head>
<style type="text/css">
    .m_item{
        width: 45%;
    }
    #body{

        width: 600px;
        margin: auto;
    }
    body{
        background: #e2e2e2;
    }
    .layui-layer-content{
        color: red;
    }
</style>
<body class="">

<div id="body">
<div class="layui-tab layui-tab-card ">
  <ul class="layui-tab-title  layui-bg-cyan">
    <li class="m_item">模拟销售</li>
    <li  class="m_item">                    销售数据</li>

  </ul>

  <div class="layui-tab-content" style="min-height: 10rem">
      <!--tab-1-->
<div class="layui-tab-item  layui-show">

<div id="product">

<form id="order" class="layui-form" onsubmit="return sub_order(this);" lay-filter="choose">

    <select name="Server" lay-verify="required">
        <option value="">请选择一个供应商</option>
        %for s in S:
        <option value="{{s['SNO']}}">{{s['CITY']}}{{s['SNAME']}}</option>
        %end

    </select>


    <select name="part" lay-verify="required">
        <option value="">请选择你需要的零件</option>
        %for p in P:
        <option value="{{p['PNO']}}">{{p['PNAME']}}</option>
        %end
    </select>
    <select name="project" lay-verify="required">
        <option value="">请选择你项目</option>
        %for j in J:
        <option value="{{j['JNO']}}">{{j['JNAME']}}</option>
        %end
    </select>
    <select name="balance" lay-verify="required">
        <option value="">请选择质量等级</option>
        %for b in B:
        <option value="{{b['PRICE']}}">{{b['LEVEL'].strip()}}等 {{b['PRICE']}}元/个</option>
        %end

    </select>
    <input type="number" name="quantity" placeholder="请输入数量" lay-verify="required" class="layui-input">
    <button class="layui-btn layui-btn-normal" lay-submit>下单</button>

</form>


    </div>


    </div>
      <!--tab-2-->

      <!--tab-3-->
    <div class="layui-tab-item ">
        <form id="sql_form" class="layui-form" onsubmit="return sql(this);">
            <div class="layui-form-item">


                    <select name="table" lay-verify="">
                        <option value="">选择查询表</option>
                        %for t in tables:
                        <option value="{{t['name']}}">{{t['name']}}</option>
                        %end

                    </select>

            </div>
            <button class="layui-btn-normal layui-btn" width="100%">测试</button>
        </form>
        <div id="sql_result">

        </div>


    </div>

  </div>
</div>
</div>



</body>
<script src="/static/layui.js"></script>
<script src="/static/help.js"></script>
<script>
    $ = layui.jquery

//tab1
function sub_order(form) {
    var order={
        S:form['Server'].value,
        P:form['part'].value,
        J:form['project'].value,
        B:form['balance'].value,
        N:form['quantity'].value,
    }
    apipost('creat_order',order,function (res) {
        info(res)
    })
    return false
}
//tab2

//tab3
function sql(form) {
    var t_n = form['table'].value
    if(!t_n){
        msg("no select")
        return false
    }
    data = {t_name:t_n}
    apipost('get_table', data, function (data) {
        log(data)
        $("#sql_result").empty()
        data.forEach(function (item) {
            $("#sql_result").append(JSON.stringify(item) + '<hr/>')
        })


    })

    return false
}



</script>
</html>